<template>
  <a-list
    size="large"
    rowKey="id"
    :loading="loading"
    itemLayout="vertical"
    :dataSource="data"
  >
    <ListItem :key="item.id" slot="renderItem" slot-scope="item">
      <template slot="actions">
      </template>
      <ListItem-meta>
        <a slot="title" href="https://vue.ant.design/">{{ item.title }}</a>
        <template slot="description">
          <span>
            <Tag>Ant Design</Tag>
            <Tag>设计语言</Tag>
            <Tag>蚂蚁金服</Tag>
          </span>
        </template>
      </ListItem-meta>
      <article-list-content :description="item.description" :owner="item.owner" :avatar="item.avatar" :href="item.href" :updateAt="item.updatedAt" />
    </ListItem>
    <div slot="footer" v-if="data.length > 0" style="text-align: center; margin-top: 16px;">
      <Button @click="loadMore" :loading="loadingMore">加载更多</Button>
    </div>
  </a-list>
</template>

<script>
import { ArticleListContent } from '@/components'

export default {
  name: 'Article',
  components: {
    ArticleListContent
  },
  data () {
    return {
      loading: true,
      loadingMore: false,
      data: []
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    getList () {
      this.$http.get('/list/article', { baseURL: '/' }).then(res => {
        this.data = res.result
        this.loading = false
      })
    },
    loadMore () {
      this.loadingMore = true
      this.$http.get('/list/article', { baseURL: '/' }).then(res => {
        this.data = this.data.concat(res.result)
      }).finally(() => {
        this.loadingMore = false
      })
    }
  }
}
</script>

<style scoped>

</style>
